<?php
/**	
*	FILENAME: 		/server_app/account_balances.php
*	DESCRIPTION:	This backend script produces a JSON response representing a listing of the transactions on a given Wildcard account.
*	AUTHOR:			Casey Burkhardt
*	VERSION:		1.0.0
*	LAST MODIFIED:	1/2/2010
**/

require_once($_SERVER['DOCUMENT_ROOT'] . "/libraries/functions.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/libraries/wildcard.php");

enforceSSL();

$studentID = $_POST["studentID"];
$password = $_POST["password"];
$accountID = $_POST["accountID"];

if ((strlen($studentID) == 0) || (strlen($password) == 0)) {
	$response["response_type"] = "error";
	$response["error_desc"] = "Student ID or password not provided.";
	echo json_encode($response);
	die();
} else if (strlen($accountID) == 0) {
	$response["response_type"] = "error";
	$response["error_desc"] = "Account ID not provided.";
	echo json_encode($response);
	die();
} else {
	// Create a Wildcard Office session with the student ID and pin provided.
	$sessionData = getWildcardSession($studentID, $password);

	// Validate the session.
	if ($sessionData === FALSE) {
		$response["response_type"] = "error";
		$response["error_desc"] = "Invalid Wildcard Office login information provided.";
		echo json_encode($response);
		die();
	} else {
		$transactionData = getTransactionDetails($sessionData, $accountID);
		// Validate the data result.
		if ($transactionData === FALSE) {
			$response["response_type"] = "error";
			$response["error_desc"] = "Unable to obtain transaction details.";
			echo json_encode($response);
			die();
		} else {
			// Encode and return the transaction data.
			$response["response_type"] = "success";
			$response["account_data"] = $transactionData;
			echo json_encode($response);
			die();
		}
	}
}

?>